package com.hw.frame.api;

import org.kymjs.kjframe.KJHttp;
import org.kymjs.kjframe.http.HttpCallBack;
import org.kymjs.kjframe.http.HttpParams;

import com.hw.frame.app.AppException;
import com.hw.frame.app.AppHttpCallBack;
import com.hw.frame.model.Base;
/**
 * 
* @ClassName: ApiClient 
* @Description: 封装网络请求
* @author hhx518
* @date 2015年4月28日 上午10:55:04 
*
 */


public class ApiClient {
	private static void doGet(String url, HttpParams params,
			HttpCallBack callBack) throws AppException {
		try {
			KJHttp kjh = KJHttp.create();
			kjh.post(url, params, callBack);
		} catch (Exception e) {
			if (e instanceof AppException)
				throw (AppException) e;
			throw AppException.network(e);
		}
	}
	private static void doPost(String url, HttpParams params,
			HttpCallBack callBack) throws AppException {
		try {
			KJHttp kjh =KJHttp.create();
			kjh.post(url, params, callBack);
		} catch (Exception e) {
			if (e instanceof AppException)
				throw (AppException) e;
			throw AppException.network(e);
		}
	}
 /**
 * 
 * @param url 请求地址
 * @param params 参数
 * @param cls   解析的实体类
 * @param proccessor  逻辑处理
 * @throws AppException   异常
 */
   //post 请求高度封装   请求完毕直接解析出实体类
	public static <T extends Base> void doPost(String url,HttpParams params, Class<T> cls,
			final LogicProccessor<T> proccessor) throws AppException {
		    doPost(url, params,new AppHttpCallBack<T>(proccessor, cls));
	}

}
